#include "BulletTouchThread.h"


BulletTouch::BulletTouch(QList<Bullet*> bul, QList<SmallEnemy*> emy,QList<FollowSmallEnemy*> fsmEmy,QList<BigEnemy*>bgEmy)
{
    BulletList = bul;
    SmallEnemySetList = emy;
    FollowEnemySetList = fsmEmy;
    BigEnemySetList = bgEmy;
}

void BulletTouch::SendBullet(QList<Bullet *> bls)
{
    BulletList = bls;
}

void BulletTouch::run()//槽函数
{

    for(int i=0;i<BulletList.length();i++){
        if(BulletList[i]->isVisible()){
            for(int j=0;j<SmallEnemySetList.length();j++){
                if(SmallEnemySetList[j]->isVisible()){
                    if(SmallEnemySetList[j]->collidesWithItem(BulletList[i])){
                        qDebug("发生碰撞");
                        SmallEnemySetList[j]->setBlood(BulletList[i]->damage);
                        BulletList[i]->setVisible(false);
                        //BulletList[i]->enemyspark->CallSpark();
                        //BulletList[i]->enemyspark->setRotation(-BulletList[i]->rotation());
                        //BulletList[i]->enemyspark->setPos(BulletList[i]->mapToScene(0,0));
                        //qDebug()<<BulletList[i]->enemyspark->isVisible();
                        if(SmallEnemySetList[j]->current_blood<=0){
                            SmallEnemySetList[j]->setVisible(false);
                        }

                    }
                }
            }
            for(int j=0;j<FollowEnemySetList.length();j++){
                if(FollowEnemySetList[j]->isVisible()){
                    if(FollowEnemySetList[j]->collidesWithItem(BulletList[i])){
                        //qDebug("发生碰撞");
                        FollowEnemySetList[j]->setBlood(BulletList[i]->damage);
                        BulletList[i]->setVisible(false);
                        //BulletList[i]->enemyspark->CallSpark();
                        //BulletList[i]->enemyspark->setRotation(-BulletList[i]->rotation());
                        //BulletList[i]->enemyspark->setPos(BulletList[i]->mapToScene(0,0));
                        if(FollowEnemySetList[j]->current_blood<=0){
                            FollowEnemySetList[j]->setVisible(false);
                        }

                    }
                }
            }
            for(int j=0;j<BigEnemySetList.length();j++){
                if(BigEnemySetList[j]->isVisible()){
                    if(BigEnemySetList[j]->collidesWithItem(BulletList[i])){
                        //qDebug("发生碰撞");
                        BigEnemySetList[j]->setBlood(BulletList[i]->damage);
                        BulletList[i]->setVisible(false);
                        //BulletList[i]->enemyspark->CallSpark();
                        //BulletList[i]->enemyspark->setRotation(-BulletList[i]->rotation());
                        //BulletList[i]->enemyspark->setPos(BulletList[i]->mapToScene(0,0));
                        if(BigEnemySetList[j]->current_blood<=0){
                            BigEnemySetList[j]->setVisible(false);
                        }
                    }
                }
            }
        }
    }
}
